home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Gekkan Dennou Club 142
/
Gekkan Dennou Club - 2000.3 Vol. 142 (Japan).7z
/
Gekkan Dennou Club - 2000.3 Vol. 142 (Japan) (Track 1).bin
/
tools
/
s_tool
/
scsicmd.c
< prev
next >
Wrap
Text File
|
1999-06-11
|
10KB
|
362 lines
#include "JX250.H"
#include <sys\iocs.h>
#include <sys\scsi.h>
#include <stdio.h>
#include <stdlib.h>
int request_disp( int );
int _scsi_cmd( int, int, unsigned char *, int, unsigned char * );
int _scsi_cmd_sm();
/***************************************
JX250 自動検索
si = 検索始めの ID
[out] ID ; あった
ID+0x8000 ; あったが、今は使えない?!
ID+0xC000 ; あったが、今はリザーブされている
-1 : なかった
****************************************/
int AutoSreachJX(si,gg)
int si,gg;
{
int i,j,m,n,id,l,oid,d,jx;
UNchar buf[128];
l=(TWOSCHK()==-2)?15:7;
oid=-1;
for(d=-1;d<=l;d++){
if ( d<0 )
id=si;
else id=d;
if ( id<0 )
continue;
//---- inquiry チェック
BUSYS( i=_scsi_inquiry(36,id,buf) );
if ( i<0 )
continue;
if ( i!=0 ){
//printf("inquiryでエラー(%d)\n",i);
if ( i==2 ) request_disp2(id);
continue;
}
if ( buf[0]!=0x06 )
continue;
if ( strncmp(&buf[8],"SHARP",5)!=0 )
continue;
jx=999;
if ( strncmp(&buf[16],"JX270",5)==0 )
jx=_JX270_;
if ( strncmp(&buf[16],"JX250",5)==0 )
jx=_JX250_;
if ( strncmp(&buf[16],"JX350",5)==0 )
jx=_JX350_;
if ( strncmp(&buf[16],"JX330",5)==0 )
jx=_JX330_;
if ( strncmp(&buf[16],"JX325",5)==0 )
jx=_JX325_;
if ( strncmp(&buf[16],"JX-325",6)==0 )
jx=_JX325_;
if ( jxscanner_>=0 ){
if ( jxscanner_!=jx )
jx=999;
}
if ( jx==999 )
continue;
jxscanner=jx; // 0;jx250 1;jx350 -1;jx330
//---- JXスキャナを発見
//---- dummy 発行
BUSYS( i=_scsi_request( 22,id,buf) );
//---- testunit 発行
BUSYS( i=_scsi_testunit(id) );
if ( i!=0 ){
oid=id;
continue;
}
//-ロゴ変更
JxLogoChain();
return(id);
}
if ( oid>=0 )
return(0x8000+id);
if ( gg!=0 ){
Dialog( "サポート出来るス",
"キャナは接続されて",
"いないようです。",
1
);
}
return(-1);
}
/**************************************************
_scsi_reseveunit(id)
**************************************************/
int _scsi_reseveunit(id)
int id;
{
static UNchar cm[6]={0x16,0,0,0,0,0};
return( _scsi_cmd( id, 6,cm,0,0 ) );
}
/**************************************************
_scsi_releaseunit(id)
**************************************************/
int _scsi_releaseunit(id)
int id;
{
static UNchar cm[6]={0x17,0,0,0,0,0};
return( _scsi_cmd( id, 6,cm,0,0 ) );
}
/**************************************************
_scsi_setwindow(id,length,bufadds)
**************************************************/
int _scsi_setwindow(id,length,bufadds)
int id,length;
UNchar *bufadds;
{
static UNchar cm[10]={0x24,0,0,0, 0,0, 0,0,0, 0};
cm[6]=(length/0x10000)&0xFF;
cm[7]=(length/0x100) &0xFF;
cm[8]= length &0xFF;
return( _scsi_cmd( id, 10,cm, (length|DATAOUT),bufadds ) );
}
/**************************************************
_scsi_getwindow(id,length,bufadds)
**************************************************/
int _scsi_getwindow(id,length,bufadds)
int id,length;
UNchar *bufadds;
{
if ( jxscanner!=_JX270_ ){
static UNchar cm[10]={0x25,0,0,0, 0,0, 0,0,0, 0};
cm[6]=(length/0x10000)&0xFF;
cm[7]=(length/0x100) &0xFF;
cm[8]= length &0xFF;
return( _scsi_cmd( id, 10,cm, (length|DATAIN),bufadds ) );
}
// JX270 は getwindow 命令、無い(汗)。
}
/**************************************************
_scsi_send(id,dtc,dtq,length,bufadds)
**************************************************/
int _scsi_send(id,dtc,dtq,length,bufadds)
int id,dtc,dtq,length;
UNchar *bufadds;
{
static UNchar cm[10]={0x2A,0,0,0, 0,0, 0,0,0, 0};
cm[2]=dtc;
*(UNshort*)&cm[4]=dtq;
cm[6]=(length/0x10000)&0xFF;
cm[7]=(length/0x100) &0xFF;
cm[8]= length &0xFF;
return( _scsi_cmd( id, 10,cm, (length|DATAOUT),bufadds ) );
}
/**************************************************
_scsi_scan(id)
**************************************************/
int _scsi_scan(id)
int id;
{
static UNchar cm[10]={0x1B,0,0,0, 0,0};
return( _scsi_cmd( id, 6,cm, 0 ,0 ) );
}
/**************************************************
_scsi_scanread(id,dtc,dtcq,length,bufadds)
**************************************************/
int _scsi_scanread(id,dtc,dtcq,length,bufadds)
int id,dtc,dtcq,length;
UNchar *bufadds;
{
static UNchar cm[10]={0x28,0,0,0, 0,0, 0,0,0, 0};
cm[2]=dtc;
*(UNshort*)&cm[4]=dtcq;
cm[6]=(length/0x10000)&0xFF;
cm[7]=(length/0x100) &0xFF;
cm[8]= length &0xFF;
return( _scsi_cmd( id, 10,cm, (length|DATAIN),bufadds ) );
}
/*++++*/
int _scsi_scanread27(id,dtc,dtcq,length,bufadds)
int id,dtc,dtcq,length;
UNchar *bufadds;
{
static UNchar cm[10]={0x28,0,0,1, 0,0, 0,0,0, 0};
cm[2]=dtc;
*(UNshort*)&cm[4]=dtcq;
cm[6]=(length/0x10000)&0xFF;
cm[7]=(length/0x100) &0xFF;
cm[8]= length &0xFF;
return( _scsi_cmd( id, 10,cm, (length|DATAIN),bufadds ) );
}
/**************************************************
_scsi_initialize(id):JX250,350 特有のもの
**************************************************/
int _scsi_initialize(id)
int id;
{
if ( jxscanner==_JX250_ || jxscanner==_JX350_ ){
static UNchar cm[10]={0xFF,0,0,0,0, 0,0,0,0,0};
return( _scsi_cmd( id,10,cm,0,0 ) );
} elif ( jxscanner==_JX330_ || jxscanner==_JX270_ ){
static UNchar cm[6]={0x00,0,0,0,0,0};
int i;
// i=_scsi_msg_reset( id,6,cm);
request_disp2(id); //dummy 発行
request_disp2(id); //dummy 発行
}
return( 0 );
}
/***************************************************
***************************************************/
asm("
.globl _TWOSCHK
_TWOSCHK:
move.l #$001E,d1
moveq #$f5,d0
trap #15
rts
");
/************************************************
REQUEST
************************************************/
int request_disp(id)
int id;
{
static char *REQUEST_MSG[17] = {
"No Se(0): 装置には、異常は、なかった\n",
"Recovered Error (1): 装置自体のリトライ機能によりコマンドが正常に終了した\n",
"Not Ready (2): 装置自体に異常が発生し、オペレータの介入が必要であることを示"
"す\n",
"Medium Error (3): リード/ライト動作時において媒体に起因するエラーが発生し、"
"リトライでエラーが回復できなかった\n",
"Hardware Error (4): 装置のハードウェアに障害が発生し、コマンドの実行が正常終"
"了しなかった\n",
"Illegal Request(5):イニシエータからのコマンド・データに異常があり、コマンドの"
"実行ができなかった\n",
"Unit Attention (6): 装置がリセットされたことを示す。又メディアが入れ換えられた"
"ことも示す\n",
"Write Protected (7): ライト・プロテクト状態にあるときにライト動作を含むコマンド"
"を受け取ったことを示す\n",
"Blank Check (8): 読みだし中にブランク領域になった。又は、書き込み中にブランク領"
"域でない領域になった\n",
"Vendor Unique (9): メーカーごとに自由に使用可\n",
"Copy Aborted (A): Copy,Compare,Copy & Verifyコマンドがデバイス異常により中止し"
"た\n",
"Aborted Command (B): ターゲットがイニシエータからのコマンドをアボートしたこと"
"を示す\n",
"Equal (C): Searchコマンドで一致を検出した\n",
"Volume Overflow (D): データがバッファに残っているのに、デバイスは最終ブロック"
"に達してしまった\n",
"Miscompare (E): ソースデータとメディアから読み出したデータが一致しない\n",
"(F): 将来の拡張用\n",
"センス・コマンドでエラーが、発生しました。\n"
};
UNchar buf[256];
int sense,sensecode,qualifier;
if ( _scsi_request( 22, id, buf ) == 0 )
sense = (unsigned int)( buf[2] & 0x0f );
else sense = 16;
sensecode=buf[12];
qualifier=buf[13];
printf("Check Condition!! Sense Key = %2Xh\n",sense);
printf(" Sense code(ASC) = %2Xh\n",sensecode);
printf(" Qualifier(ASCQ) = %2Xh\n",qualifier);
printf(" Infomation = %02X%02X%02X%02Xh\n",buf[3],buf[4],buf[5],buf[6]);
printf( REQUEST_MSG[sense] );
return( sense*0x10000+sensecode*0x100+qualifier );
}
/*+++++*/
int request_disp2(id)
int id;
{
UNchar buf[256];
int sense,sensecode,qualifier;
//
if ( _scsi_request( 22, id, buf ) == 0 )
sense = (unsigned int)( buf[2] & 0x0f );
else sense = 16;
sensecode=buf[12];
qualifier=buf[13];
return( sense*0x10000+sensecode*0x100+qualifier );
}
/*******************************************************
int scsi_cmd(
int id
SCSI-ID
int len
CDB の長さ
unsigned char *buf
CDB のアドレス
int rlen
データ読み込みの場合、バイト数
データ書き込みの場合、バイト数|0x80000000
0ならデータ読み込み無し
unsigned char *buf2
データアドレス
********************************************************/
int _scsi_cmd( int id, int len, unsigned char *buf, int rlen, unsigned char *buf2 )
{
int rc;
register int ID asm("d4");
/* セレクションフェーズ */
ID=id;
rc = _scsi_select( ID );
if ( rc!=0 ) return(-1);
/* コマンドフェース */
buf[1]=(buf[1]&0x1F)|(ID/0x10000*0x20);
rc = _scsi_cmdout( len, buf );
if ( rc!=0 ) return(-1);
if( rlen != 0 ){
if ( rlen>0 ){
/* データインフェーズ */
rc = _scsi_datain( rlen, buf2 );
if ( rc==-1 )
return(-1);
if ( rc==-2 ){
rc=_scsi_cmd_sm();
if ( rc!=0 )
return(rc);
return(-2);
}
} else {
/* データアウトフェーズ */
rc = _scsi_dataout( rlen&0x7FFFFFFF, buf2 );
if ( rc==-1 )
return(-1);
if ( rc==-2 ){
rc=_scsi_cmd_sm();
if ( rc!=0 )
return(rc);
return(-2);
}
}
}
return( _scsi_cmd_sm() );
}
/*++++++++++++++*/
int _scsi_cmd_sm()
{
unsigned char status,msg;
int rc;
/* ステイタスフェーズ */
rc = _scsi_stsin( &status );
if ( rc!=0 ) return(-1);
/* メッセージフェーズ */
rc = _scsi_msgin( &msg );
if ( rc!=0 ) return(-1);
return( msg*0x10000 + status );
}
/*+++++++++++*/
int _scsi_msg_reset( int id, int len, unsigned char *buf)
{
int rc;
unsigned char status,msg;
/* セレクションフェーズ */
rc = _scsi_select_atn( id );
if ( rc!=0 ) return(-1);
/* メッセージアウトフェーズ */
msg=0x0C;
rc = _scsi_msgout( &msg );
return(0);
}